package com.siki.Config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author Siki
 * @date 2020/12/22
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig  extends WebMvcConfigurationSupport{
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.siki"))
                .paths(PathSelectors.any())
                .build();
    }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("swagger-ui.html")
        .addResourceLocations("classpath:/META-INF/resources/");
    //springboot 集成swagger2.2后静态资源404，添加如下两行配置
    registry.addResourceHandler("/**")
    .addResourceLocations("classpath:/static/");

    registry.addResourceHandler("/webjars/**")
        .addResourceLocations("classpath:/META-INF/resources/webjars/");
    super.addResourceHandlers(registry);
  }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("大数据作业 API文档")
                .description("大数据作业 API文档")
//                .contact(new Contact("七仔", "https://7mage.xyz", "934913797@qq.com"))
                .version("1.0")
                .build();
    }
}